package com.mycompany.app.webapp.action.person;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;

import com.mycompany.app.manager.PersonManager;

import junit.framework.TestCase;

public abstract class BaseActionTestCase extends TestCase {

	protected Mockery context;
	protected PersonManager personManager;

	public BaseActionTestCase() {
		super();
	}

	public BaseActionTestCase(String name) {
		super(name);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		
		context = new JUnit4Mockery();
		context.setImposteriser(ClassImposteriser.INSTANCE);
		
		personManager = context.mock(PersonManager.class);
		
		setUpAction();
	}

	protected abstract void setUpAction();

	@Override
	protected void tearDown() throws Exception {
		personManager = null;
		
		super.tearDown();
	}

	protected void failException(Exception e) {
		StringWriter stringWriter = new StringWriter();
		PrintWriter printWriter = new PrintWriter(stringWriter);
		e.printStackTrace(printWriter);
		fail(printWriter.toString());
	}

}